<div class="content last ui-widget-content">
	<div class="content-full">
		<div style="width: 98%;padding-left: 5px;">
			<?php if (count($this->arrError)>0) echo $this->error($this->arrError); ?>
			<div class="cms_table">
				<?php if ($this->Obj['isupdate'] == 0){?>
						<h2> Thêm mới lịch thi</h2> 
						<?php }?>
				<?php if ($this->Obj['isupdate'] == 1){?>
						<h2> Chỉnh sửa thông tin lịch thi</h2> 
						<?php }?>
				<form action="<?php echo BASE_URL; ?>/<?php echo $this->controller;?>/<?php echo $this->action;?>"	method="POST" id="shedule-form">
					<input type="hidden" name="id" value="<?php echo $this->Obj['id'] ;?>">		
					<input type="hidden" name="isupdate" value="<?php echo $this->Obj['isupdate'];?>"/>			
					<table cellpadding="0" cellspacing="0">
						<tr><td class="label">
								Tên lịch thi: 
								</td><td class="field_container"><input type="text"  name="name" style="width: 300px "   value="<?php  echo $this->Obj['name']; ?>" >
						</td></tr>
						<tr><td class="label">
								Khóa học: 
								</td><td class="field_container"><?php echo $this->SltCourse("course_id", $this->Obj['course_id'],1); ?>
						</td></tr>
						<tr><td class="label">
								Kỳ thi: 
								</td><td class="field_container"><?php echo $this->SltExam("exam_id", $this->Obj['exam_id']); ?>
						</td></tr>
						<tr><td class="label">
								Lớp thi: 
								</td><td class="field_container"><?php echo $this->SltClass("class_id", $this->Obj['class_id']); ?>
						</td></tr>
						<tr><td class="label">
								 Thời gian bắt đầu lịch thi: 
								</td><td class="field_container"><input type="text" id="datepicker1" name="time_start"  style="width: 200px "   value="<?php  echo $this->Obj['time_start']; ?>" >
						</td></tr>
						<tr><td class="label">
								 Thời gian kết thúc lịch thi: 
								</td><td class="field_container"><input type="text" id="datepicker2" name="time_end"  style="width: 200px "   value="<?php  echo $this->Obj['time_end']; ?>" >
						</td></tr>
						<tr><td class="label">
								Người tạo:  
								</td><td class="field_container"><input type="text" name="created_user"  style="width: 200px "   value="<?php  echo $this->Obj['created_user']; ?>" >
						</td></tr>
						<tr><td class="label">
								Mở lịch thi: 
								</td><td class="field_container"> <input type="checkbox" name="hidden" <?php if($this->Obj['hidden']=='on') echo "checked='checked'"; ?> >
						</td></tr>
						<tr><td colspan="0">
								<p>
									<label>Ghi chú:</label>
									<textarea class="editor" name="note" rows="3" cols="20"><?php  echo $this->Obj['note']; ?></textarea>
								</p>
						</td></tr>
						<tr>
							<td colspan="2">
								<fieldset>
									<legend>Danh sách đề thi </legend>
								<dl>
									<!-- CMS -->
									<input type="hidden" id="CMS_SERVERSIDE" value="<?php echo BASE_URL;?>/test/serverside">
									<?php echo $this->table("table_test_sheduleexam",$this->cols_view_title_test,"test");?>
									<script language="javascript">
										$(document).ready(function(){
											InitJqueryDataTable("#table_test_sheduleexam","");
										});
														
									</script>
									<!-- CMS -->
									<br/>
									<input type="button" value="Thêm đề thi vào danh sách đề" onclick="fnAddTestToShedule(); return false;"/>
								</dl>
								</fieldset>
							</td>
						</tr>
						<tr><td colspan="2">
								<fieldset>
									<legend>Danh sách đề thi được chọn</legend>
									<dl>
										<table id="table_selected_test" class="datatable">
											<tr>
												<th>Đề chính thức</th>
												<th>Tiêu đề</th>
												<th>Thao tác</th>
											</tr>
											<?php
												$list_test_id  = explode(',',$this->Obj['list_test_id']);
												$models_test = new Default_Models_Test();
												if(!empty($list_test_id[0]))
												if(count($list_test_id)>0)
												foreach($list_test_id as $key=>$list_test_idItem){
													$models_test->find("id",$list_test_idItem);
											 ?>
											<tr>
												<td>
													<input type="hidden" class="list_test_id_selected" id="list_test_id_selected_<?php echo $list_test_idItem;?>" name="list_test_id[]" value="<?php echo $list_test_idItem;?>">
													<input type="radio" class="rdDechinhThuc" name="rdDechinhThuc" value="<?php echo $list_test_idItem;?>" <?php if($key==0)  echo 'checked="checked"'; ?>/>
												</td>
												<td><?php echo $models_test->getTitle(); ?></td>
												<td style="text-align: center;">
													<a href="#"  onclick="removeRowTestSelected(this);return false;">
														<img class="fugue fugue-cross"  alt="Xóa"       src="<?php echo BASE_URL; ?>/img/icons/space.gif"/>
													</a> 
												</td>
											</tr>
											<?php } ?>
										</table>
									</dl>						
								</fieldset>
								
						</td></tr>						
						
						<tr><td colspan="5"  style="font-size: 12px; color: white; font-family: tahoma;"  >
							<p align="center">
								<input  type="submit" value="Đồng ý" onclick="beforeSubmitAddShedule(); return false;" style="font-size: 15px;" class="add-answer-icon ui-state-default ui-corner-all">&nbsp;&nbsp;&nbsp;&nbsp;
								<input  type="button" value="Hủy bỏ" onclick="window.location='<?php echo  BASE_URL.'/sheduleexam';  ?>'" style="font-size: 15px;" class="add-answer-icon ui-state-default ui-corner-all">
							</p>
						</td></tr>
						
					</table>	
				</form>
				<!--  -->
			</div>
		</div>
	</div>
</div>

<script type="text/javascript">
<!--

$(document).ready(function(){
	$("#course_id").change(function(){
		$.ajax({
    				type: "POST",
    				url: $("#BASE_URL").val()+"/exam/getinfocourse"+"/token/"+fnGenToken(),
    				data: "course_id="+$("#course_id").val(),
    				dataType: "json",
    				success: function(data){
	    				if(data['success']==true){
	    				}else
	    					alert("Có lỗi "+data['error']); 
    				}
				});					
		
	});
});

function fnAddTestToShedule(){
    	arrItem = new Array();
    	$("#table_test_sheduleexam tbody").find(".check_row").each(function(){
			is_check = $(this).attr("checked");
			if(is_check==true){
				checkbox_id  = $(this).attr('id');
				arrItem.push(checkbox_id.replace("checkbox_row",""));
			}    
		});
		if(arrItem.length>0){
			var count_exists = 0;
			for(i=0;i<arrItem.length;i++){
				var test_id    = arrItem[i];
				var a 		   = $("#checkbox_row"+test_id);
				var test_title = a.parent("td").prev().prev().html();	
				if($("#list_test_id_selected_"+test_id).size()==0){ // chuưa tồn tại trong danh sách đã chọn
						html ='<tr>';
						html+='<td>';
						html+='		<input type="hidden" class="list_test_id_selected" id="list_test_id_selected_'+test_id+'" name="list_test_id[]" value="'+test_id+'">';
						
						html+='		<input type="radio" class="rdDechinhThuc"  name="rdDechinhThuc" value="'+test_id+'"/>';
						html+='	</td>';
						html+='	<td>'+test_title+'</td>';
						html+='	<td style="text-align: center;">';
						html+='		<a href="#" onclick="removeRowTestSelected(this);return false;">';
						html+='			<img class="fugue fugue-cross"  alt="Xóa"       src="'+$("#BASE_URL").val()+'/img/icons/space.gif"/>';
						html+='		</a>';
						html+='	</td>';
						html+='</tr>';
						$("#table_selected_test tr:last").after(html);
				}else count_exists++;
			}
			/*
			if(count_exists>0)
				alert("Bạn chọn trùng "+count_exists+" bài thi.");
			*/			
		}else
			alert("Chưa chọn bài thi.");		
}
function removeRowTestSelected(this_){
	if(confirm("Bạn có chắc chắn muốn xóa không?"))
		$(this_).parent("td").parent("tr").remove();
}

function beforeSubmitAddShedule(){
	var ok = false ;
	var count = 0;
	$(".rdDechinhThuc").each(function(){
		count ++ ;
		if($(this).attr("checked") == true )
			ok=true;
	});
	if(count==0)  ok=true;
	if(ok == true)
			$("#shedule-form").submit();
	else
		alert("Chưa chọn đề chính thức");
	return false;
}
//-->
</script>

